﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Benefit.ViewModel.Month
{
    public class MonthXingNeng
    {
        /// <summary>
        /// 左侧菜单显示信息
        /// </summary>
        public LeftMenuInfos LeftMenuInfos { get; set; }

        public string QueryDate { get; set; }

        public string Pdate { get; set; }

        public string QueryYear { get; set; }

        public string QueryMonth { get; set; }

        public Models.Sys.Operator Operator { get; set; }
        /// <summary>
        /// 交易员月度交易信息
        /// </summary>
        public Models.View.OperatorMonthSum OperatorMonthSum { get; set; }
        /// <summary>
        /// 交易员上月月度交易信息
        /// </summary>
        public Models.View.OperatorMonthSum PreOperatorMonthSum { get; set; }
        /// <summary>
        /// 交易员去年同期交易信息
        /// </summary>
        public Models.View.OperatorMonthSum PreYearOperatorMonthSum { get; set; }

        public string LastDate { get; set; }
        /// <summary>
        /// 页面脚本
        /// </summary>
        public string JS { get; set; }


        #region 定义一些使用到的接口
        private Interface.Sys.ITradeHistory ITradeHistory = null;
        private Interface.Sys.IOperator IOperator = null;
        private Interface.View.IOperatorMonthSum IOperatorMonthSum = null;
        private Interface.View.IOperatorDayChange IOperatorDayChange = null;
        private Interface.View.IOperatorDayTradeInfo IOperatorDayTradeInfo = null;
        #endregion


        public MonthXingNeng(int operatorId, int queryDate, DB.DBManager db)
        {
            this.QueryMonth = queryDate.ToString().Substring(4, 2);
            this.QueryYear = queryDate.ToString().Substring(0, 4);
            this.QueryDate = queryDate.ToString();
            this.Operator = IOperator.GetModel(operatorId);
            this.OperatorMonthSum = IOperatorMonthSum.GetOperatorMonthSum(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear));

            int lastyear = Convert.ToInt32(this.QueryYear);
            int lastmonth = Convert.ToInt32(this.QueryMonth);
            if (Convert.ToInt32(this.QueryMonth) == 1)
            {
                lastmonth = 12;
                lastyear = lastyear - 1;
            }
            else
            {
                lastmonth = lastmonth - 1;
            }
            this.PreOperatorMonthSum = IOperatorMonthSum.GetOperatorMonthSum(operatorId, lastmonth, lastyear);

            int qunian = Convert.ToInt32(this.QueryYear) - 1;

            this.PreYearOperatorMonthSum = IOperatorMonthSum.GetOperatorMonthSum(operatorId, Convert.ToInt32(this.QueryMonth), qunian);

            //Models.Sys.TradeHistory th = ITradeHistory.GetLastTradeHistoryDateString();

            List<Models.View.OperatorDayChange> operatorDayChanges = IOperatorDayChange.GetOperatorDayChange(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear));

            this.JS += Benefit.Tools.ChartAtManager.ChartManager.ShouYiBiLVLine(operatorDayChanges);

            List<Models.View.OperatorDayTradeInfoData> winDatas = IOperatorDayTradeInfo.GetMonthOperatorDayTradeInfoData(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear), true);

            this.JS += Benefit.Tools.ChartAtManager.ChartManager.GetOperatorAllBenefitPie(winDatas, true);

            List<Models.View.OperatorDayTradeInfoData> loseDatas = IOperatorDayTradeInfo.GetMonthOperatorDayTradeInfoData(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear), false);

            this.JS += Benefit.Tools.ChartAtManager.ChartManager.GetOperatorAllBenefitPie(winDatas, false);

        }



        private void InitInterface(DB.DBManager db)
        {
            #region 初始化接口
            ITradeHistory = new Service.Sys.ServiceTradeHistory(db);
            IOperator = new Service.Sys.ServiceOperator(db);
            IOperatorMonthSum = new Service.View.ServiceOperatorMonthSum(db);
            IOperatorDayChange = new Service.View.ServiceOperatorDayChange(db);
            IOperatorDayTradeInfo = new Service.View.ServiceOperatorDayTradeInfo(db);
            #endregion
        }
        /// <summary>
        /// 释放接口
        /// </summary>
        private void DisposeInterface()
        {
            #region 释放接口
            ITradeHistory = null;
            IOperator = null;
            IOperatorMonthSum = null;
            IOperatorDayChange = null;
            IOperatorDayTradeInfo = null;
            #endregion
        }
    }
}
